<?php
/*
	员工中心
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
if($_RQ['op']=='main'){
	$return['setting']=$this->plugin_setting('page');
	$member=$this->model('member')->checkmember();
	$basic=model('core/member')->basic($_SESSION['uid']);
	$member=array_merge($member,$basic);
	$member['storeurl']=custom_url('jy_mjifee/myhome/main/mid='.$_SESSION['uid'].'&fromstore='.$_SESSION['uid'],true);
	$image=ROOT_AT.'oss/'.$_SESSION['uniacid'].'/images/jy_mjifee/fromstore'.$_SESSION['uid'].'.jpg';
	if(!file_exists($image)){
		$url='/jy_mjifee/myhome/index?mid='.$_SESSION['uid'].'&fromstore='.$_SESSION['uid'];
		$wxapp=pdo_get('core_account_wxapp',array('id'=>$_SESSION['wxapp_id'],'uniacid'=>$_SESSION['uniacid']));
		$res=model('core/wxapp')->appcode($url,$wxapp['appid'],$wxapp['appsecret'],200);
		$path=ROOT_AT.'oss/'.$_SESSION['uniacid'].'/images/jy_mjifee';
		if(!file_exists($path)){
			mkdir($path,0700, true);
		}
		file_put_contents($image,$res);
	}
	$return['appcode'] = 'oss/'.$_SESSION['uniacid'].'/images/jy_mjifee/fromstore'.$_SESSION['uid'].'.jpg';
	$return['member']=$member;
	$return['member']['level']=$this->get('level',array('uniacid'=>$_SESSION['uniacid'],'id'=>$member['level_id']));
	$return['member']['level']['title']=$return['member']['level']['title']?:$this->diylevelname;
	$data=array();
	//已结算佣金
	$data['balance_total']=$this->sum('balance',array('merchid'=>$_SESSION['onemerchid'],'mid'=>$_SESSION['uid']),'money');
	$data['balance_num']=$this->count('balance',array('merchid'=>$_SESSION['onemerchid'],'mid'=>$_SESSION['uid']));
	//待结算佣金
	$params=array('merchid'=>$_SESSION['onemerchid'],'uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'status'=>1);
	/*if($this->setting['balance_day']){
		//结算天数
		$time=TIMESTAMP-intval($this->setting['balance_day'])*86400;
		$params['complete_time <']=$time;
	}*/
	$data['commission_1']=$this->sum('commission',$params,'money');
	$data['commission_total']=$this->sum('commission',array('merchid'=>$_SESSION['onemerchid'],'uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']),'money');
	$data['fee0']=$this->sum('commission',array('type'=>array(0,1),'merchid'=>$_SESSION['onemerchid'],'uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']),'money');
	$data['fee2']=$this->sum('commission',array('type'=>array(2,3),'merchid'=>$_SESSION['onemerchid'],'uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']),'money');
	$data['fee4']=$this->sum('commission',array('type'=>array(4,5),'merchid'=>$_SESSION['onemerchid'],'uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']),'money');
	$data['merchallfee']=pdo_getsum('jy_weishop_order',array('ispay'=>1,'merchid'=>$_SESSION['onemerchid'],'uniacid'=>$_SESSION['uniacid']),'price');
	$month_start=strtotime(date('Ym').'01');
	$data['merchallfee2']=pdo_getsum('jy_weishop_order',array('createtime >'=>$month_start,'ispay'=>1,'merchid'=>$_SESSION['onemerchid'],'uniacid'=>$_SESSION['uniacid']),'price');
	if($return['member']['bumenid']){
		$data['merchbmfee']=$this->sum('order',array('bumenid'=>$return['member']['bumenid'],'merchid'=>$_SESSION['onemerchid'],'uniacid'=>$_SESSION['uniacid']),'order_price');
		$data['merchbmfee2']=$this->sum('order',array('createtime >'=>$month_start,'bumenid'=>$return['member']['bumenid'],'merchid'=>$_SESSION['onemerchid'],'uniacid'=>$_SESSION['uniacid']),'order_price');
	}
	$data['merchmyfee']=$this->sum('order',array('workerid OR'=>'workerid ='.$return['member']['id'].' or mid ='.$_SESSION['uid'],'merchid'=>$_SESSION['onemerchid'],'uniacid'=>$_SESSION['uniacid']),'order_price');
	$data['merchmyfee2']=$this->sum('order',array('createtime >'=>$month_start,'workerid'=>$return['member']['id'],'merchid'=>$_SESSION['onemerchid'],'uniacid'=>$_SESSION['uniacid']),'order_price');
	$data['total_price']=$this->model('model')->goods_allfee($return['member']);
	$data['total_price2']=$this->model('model')->goods_allfee($return['member'],0,1);
	//其他单品
	$goods_member=$return['member'];
	$goods_member['level']['type']=1;
	$data['goods_fee11']=$this->model('model')->goods_allfee($goods_member);
	$data['goods_fee12']=$this->model('model')->goods_allfee($goods_member,0,1);
	$data['merchmyfee'] -=$data['goods_fee11'];
	$data['merchmyfee2'] -=$data['goods_fee12'];
	$goods_member['level']['type']=2;
	$data['goods_fee21']=$this->model('model')->goods_allfee($goods_member);
	$data['goods_fee22']=$this->model('model')->goods_allfee($goods_member,0,1);
	if($return['member']['bumenid']){
		$data['merchbmfee'] -=$data['goods_fee21'];
		$data['merchbmfee2'] -=$data['goods_fee22'];
	}
	$goods_member['level']['type']=3;
	$data['goods_fee31']=$this->model('model')->goods_allfee($goods_member);
	$data['goods_fee32']=$this->model('model')->goods_allfee($goods_member,0,1);
	$data['merchallfee'] -=$data['goods_fee31'];
	$data['merchallfee2'] -=$data['goods_fee32'];
	$data['merchbmfee']=$data['merchbmfee']>0?intval($data['merchbmfee']*100)/100:0;
	$data['merchmyfee']=$data['merchmyfee']>0?intval($data['merchmyfee']*100)/100:0;
	$data['merchallfee']=$data['merchallfee']>0?intval($data['merchallfee']*100)/100:0;
	$return['data']=$data;
	$return['member']['typetitle']=$this->level_types[$return['member']['level']['type']];
	set_html('title',$return['setting']['center']?:'分销中心');
	exi($return);
}

?>